package com.resou.reader.utils.diskcache;

import android.support.v4.util.LruCache;

import com.resou.reader.utils.diskcache.lru.Util;


/**
 * A class that generates and caches safe and unique string file names
 */
public class SafeKeyGenerator {
    private final LruCache<String, String> loadIdToSafeHash = new LruCache<>(100);

    public String getSafeKey(String key) {
        String safeKey;
        synchronized (loadIdToSafeHash) {
            safeKey = loadIdToSafeHash.get(key);
        }
        if (safeKey == null) {
            safeKey = Util.md5(key);
        }
        synchronized (loadIdToSafeHash) {
            loadIdToSafeHash.put(key, safeKey);
        }
        return safeKey;
    }


}
